package com.hongminzheng.openapi.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hongminzheng.openapi.mapper.TokenMapper;
import com.hongminzheng.openapi.pojo.Token;
import com.hongminzheng.openapi.service.TokenService;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author hmz
 * @version v1.0
 * @data 2020/09/29
 **/

@Service
@Transactional(rollbackFor = Exception.class)
@Log4j
public class TokenServiceImpl implements TokenService {

    @Autowired
    private TokenMapper tokenMapper;


    @Override
    public int deleteByPrimaryKey(Integer id) {
        return tokenMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Token token) {
        return tokenMapper.insert(token);
    }

    @Override
    public int insertSelective(Token token) {
        return tokenMapper.insertSelective(token);
    }

    @Override
    public Token selectByPrimaryKey(Integer id) {
        return tokenMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Token token) {
        return tokenMapper.updateByPrimaryKeySelective(token);
    }

    @Override
    public int updateByPrimaryKey(Token token) {
        return tokenMapper.updateByPrimaryKey(token);
    }

    @Override
    public PageInfo<Token> findPage(Integer pageNum, Integer pageSize, Token token){
        PageHelper.startPage(pageNum, pageSize);
        List<Token> tokens = tokenMapper.findByAccess(token);
        PageInfo<Token> pageInfo = new PageInfo<>(tokens);
        return pageInfo;
    }

}
